<?php
/**

*/
class ResetController extends App_Controller_Action
{
	public function init()
	{
		/* Initialize action controller here */
	}
	
	public function indexAction()
	{
    	$request=$this->getRequest();
    	
    	$id = $request->getParam('id');    	    		
    	$key = $request->getParam('key');
		$model_client = new Model_UserClient();
		$clientInfo = $model_client->getUser($id);
    	
		if ($clientInfo){    	
			$key2=$clientInfo['password'];
    		$email=$clientInfo['email'];
		    $this->view->email=$email;    	    		
    		if($key==$key2)
	    	{
		    	if($request->isPost())
		    	{
		    		$password = $request->getParam('password');    	 
		    		$model_client = new Model_UserClient();		    		
		    		
		    		$result = $model_client->udpatePassword($email,$password);
					
					if ($result){
						$this->_redirect("/reset/confirm");	
					}else{
						$this->view->error_msg="Sorry, password reset failed.";					
					}
						
		    	}
	    	}else{
				$this->view->error_msg="Sorry, Auth failed.";					    		
	    	}
		}else{
			$this->view->error_msg="Sorry, Auth failed.";					    					
		}
    }

	public function confirmAction()
	{
    }
	
}
